package cn.hx.mall.order.controller;

import cn.hx.mall.order.entity.Order;
import cn.hx.mall.order.entity.OrderSetting;
import cn.hx.mall.order.service.OrderReturnApplyService;
import cn.hx.mall.order.service.OrderReturnReasonService;
import cn.hx.mall.order.service.OrderService;
import cn.hx.mall.order.service.OrderSettingService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("order")
public class OrderPublicController {
    @Resource
    private OrderService orderService;
    @Resource
    private OrderSettingService orderSettingService;
    @Resource
    private OrderReturnApplyService orderReturnApplyService;
    @Resource
    private OrderReturnReasonService orderReturnReasonService;

    /**
     * 对应页面的跳转及数据填充
     */
    @GetMapping("{jsp}")
    @SuppressWarnings("all")
    public String goAndShow(Model attr, @PathVariable("jsp") String jsp, @RequestParam(defaultValue = "1") Integer page){
        switch (jsp){

            //订单列表页面
            case "orderList":

                //填装orderList数据
                Order order = new Order();
                order.setDeleteStatus(0);
                attr.addAttribute("orderList", orderService.queryAll(order));
                break;

                //订单设置页
            case "orderSetting":
                //填装orderSetting页数据
                List<OrderSetting> settings = orderSettingService.queryAll(null);
                if (settings.size() > 0) {
                    attr.addAttribute("orderSetting", settings.get(0));
                }
                break;

                //订单处理页
            case "returnApplyList":
                int size = 8;
                //填装returnApply页面数据
                attr.addAttribute("returnStatus",orderReturnApplyService.selectStatus());
                attr.addAttribute("pageModel", orderReturnApplyService.queryAllByLimit(page, size));
                break;

                //订单原因页
            case "returnReasonList":
                //填装returnReason页面数据
                attr.addAttribute("orderReturnReasonList", orderReturnReasonService.queryAll(null));
                break;

        }
        return "order/"+jsp;
    }
}
